﻿namespace AspDotNet.Core7.First.Middlewares
{
    public class ShortCircuitMiddleware
    {
        private RequestDelegate NextMiddleware { get; set; }
        public ShortCircuitMiddleware(RequestDelegate nextMiddleware)
        {
            NextMiddleware = nextMiddleware;
        }

        public async Task Invoke(HttpContext httpContext)
        {
            //if (httpContext.Request.Headers["User-Agent"].Any(v => v.Contains("Firefox")))
            if (httpContext.Items["Firefox"] as bool? == true)
            {
                httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
            }
            else
            {
                await NextMiddleware.Invoke(httpContext);
            }
        }
    }
}
